package com.happy_hao.topbiz.controller;

import com.happy_hao.topbiz.api.UserApi;
import com.happy_hao.topbiz.common.Result;
import com.happy_hao.topbiz.dto.userDto.UpdateUserRequest;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/topbiz/admin")
public class AdminController {

    @Resource
    private UserApi userApi;

    @GetMapping("/getUserInfo")
    public Result getUserInfo(@RequestParam("username") String username) {
        return userApi.getUserInfo( username);
    }

    @GetMapping("/getAllUserSimpleInfo")
    public Result getAllUserSimpleInfo() {
        return userApi.getAllUserSimpleInfo();
    }

    @PostMapping("/updateUserInfo")
    public Result updateUserInfo(@Valid @RequestBody UpdateUserRequest updateUserRequest) {
        return userApi.updateUserInfo(updateUserRequest);
    }

    @PostMapping("/addNewGroup")
    public Result addNewGroup(@RequestParam("groupName") String groupName) {
        return userApi.addNewGroup(groupName);
    }

    @GetMapping("/getAllGroups")
    public Result getAllGroups() {
        return userApi.getAllGroups();
    }

    @PostMapping("/bindUserToGroup")
    public Result bindUserToGroup(@RequestParam("groupName") String groupName,
                                  @RequestParam("username") String username) {
        return userApi.bindUserToGroup(groupName,username);
    }

    @DeleteMapping("/kickUserFromGroup")
    public Result kickUserFromGroup(@RequestParam("groupName") String groupName,
                                    @RequestParam("username")String username) {
        return userApi.kickUserFromGroup(groupName,username);
    }

    @GetMapping("/getGroupAllUsers")
    public Result getGroupAllUsers(@RequestParam("groupName") String groupName) {
        return userApi.getGroupAllUsers(groupName);
    }

    @GetMapping("/getAllPermissions")
    public Result getAllPermissions() {
        return userApi.getAllPermissions();
    }

    @PostMapping("/bindPermissionToGroup")
    public Result bindPermissionToGroup(@RequestParam("groupName") String groupName,
                                        @RequestParam("permissionName") String permissionName) {
        return userApi.bindPermissionToGroup(groupName,permissionName);
    }
    @DeleteMapping("/dropPermissionFromGroup")
    public Result dropPermissionFromGroup(@RequestParam("groupName") String groupName,
                                          @RequestParam("permissionName")  String permissionName) {
        return userApi.dropPermissionFromGroup(groupName,permissionName);
    }
}
